package com.xxx.landlord.client.view;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;

public class SelectModeView {

    @FXML
    private ImageView offlinebutton;

    @FXML
    public void initialize() {
        setupButtonActions();
    }

    private void setupButtonActions() {
        // 获取第一个按钮（单机模式）
        Button offlineButton = (Button) offlinebutton.getParent().getParent();
        offlineButton.setOnAction(event -> handleOfflineMode());

        // 获取第二个按钮
        Button onlineButton = (Button) offlineButton.getParent().getChildrenUnmodifiable().get(1);
        onlineButton.setOnAction(event -> handleOnlineMode());
    }

    // 处理联机游戏
    private void handleOnlineMode() {
        try {
            System.out.println("联机游戏模式 selected");

            FXMLLoader loader = new FXMLLoader(getClass().getResource("selectRoom.fxml"));
            Parent selectRoomRoot = loader.load();

            Stage stage = (Stage) offlinebutton.getScene().getWindow();
            stage.setScene(new Scene(selectRoomRoot));
            stage.setTitle("选择桌号");
            stage.show();

        } catch (Exception e) {
            System.err.println("无法加载选择桌号界面: " + e.getMessage());
            e.printStackTrace();
        }
    }

    // 处理单机游戏
    private void handleOfflineMode() {
        System.out.println("单机游戏模式 selected - 功能待实现");
    }
}